MODPATH=$(shell basename `pwd`)
MODNAME=$(subst mod_,lib,${MODPATH})
#LIB=${MODNAME}.so
LIB=libuos-monitor.so
MOD_PATH=pcie cpu disk memory temp net
SRCS=$(shell find . ../libs/  -maxdepth 1 | grep '\.c$$')
OBJS=$(SRCS:%.c=%.o)
#CFLAGS=--std=gnu99 -g -fPIC -shared
CFLAGS=-g -fPIC -lpthread -shared
INCLUDE=-I../libs -I./  -I../include
#INCLUDE+= $(foreach item,$(MOD_PATH),-I./$(item))
all:${LIB}
${LIB}:${OBJS}
	gcc $(CFLAGS) $(SRCS) $(INCLUDE) -o $(LIB)
%.o:%.c
	gcc -c $^ $(INCLUDE) -o $@ 
clean:
	rm -rf $(LIB) $(OBJS)

INSTALL_PATH=/usr/lib
ifdef DESTDIR
	INSTALL_PATH=$(DESTDIR)
else ifdef prefix
	INSTALL_PATH=$(prefix)
else
	INSTALL_PATH=/usr/lib
endif

install:
	mkdir -p $(INSTALL_PATH)
	install -m 755 $(LIB) $(INSTALL_PATH)/
uninstall:
	rm -f $(INSTALL_PATH)/$(LIB)

